package com.zuijin.vue2blog.common.api;

/**
 * --------------------------------------------
 * ClassName:    Result
 * CreateBy:     IntelliJ IDEA
 * Author:       醉瑾
 * Date:         2022-04-17
 * Description :
 * --------------------------------------------
 */
public class Result<T> {
    private int code;
    private String message;
    private T data;

    Result() {
    }

    Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功返回结果
     *
     * @param
     * @return
     * @date 2022/4/17
     */
    public static <T> Result<T> OK() {
        return new Result<>(ResultCode.OK.getCode(), ResultCode.OK.getMessage(), null);
    }

    /**
     * 成功返回结果
     *
     * @param data
     * @return result
     * @date 2022/4/17
     */
    public static <T> Result<T> OK(T data) {
        return new Result<>(ResultCode.OK.getCode(), ResultCode.OK.getMessage(), data);
    }

    /**
     * 成功返回结果
     *
     * @param data message
     * @return result
     * @date 2022/4/17
     */
    public static <T> Result<T> OK(T data, String message) {
        return new Result<>(ResultCode.OK.getCode(), message, data);
    }

    /**
     * 失败返回结果
     *
     * @date 2022/4/17
     */
    public static <T> Result<T> ERROR() {
        return new Result<>(ResultCode.ERROR.getCode(), ResultCode.ERROR.getMessage(), null);
    }

    /**
     * 失败返回结果
     *
     * @param message 提示信息
     * @date 2022/4/17
     */
    public static <T> Result<T> ERROR(String message) {
        return new Result<>(ResultCode.ERROR.getCode(), message, null);
    }

    /**
     * 资源丢失返回结果
     *
     * @param <T>
     * @return
     * @date 2022/4/17
     */
    public static <T> Result<T> NOT_FOUND() {
        return new Result<>(ResultCode.NOT_FOUND.getCode(), ResultCode.NOT_FOUND.getMessage(), null);
    }

    /**
     * 资源丢失返回结果
     *
     * @param message
     * @param <T>
     * @return
     */
    public static <T> Result<T> NOT_FOUND(String message) {
        return new Result<>(ResultCode.NOT_FOUND.getCode(), ResultCode.NOT_FOUND.getMessage(), null);
    }

    /**
     * 未登录或登录过期
     *
     * @param <T>
     * @return
     */
    public static <T> Result<T> UNAUTHORIZED() {
        return new Result<>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), null);
    }

    /**
     * 未登录或登录过期
     *
     * @param <T>
     * @return
     */
    public static <T> Result<T> UNAUTHORIZED(T data) {
        return new Result<>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
    }

    /**
     * 没有相关权限
     *
     * @param <T>
     * @return
     */
    public static <T> Result<T> FORBIDDEN() {
        return new Result<>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), null);
    }


    /**
     * 没有相关权限
     *
     * @param <T>
     * @return
     */
    public static <T> Result<T> FORBIDDEN(String message) {
        return new Result<>(ResultCode.FORBIDDEN.getCode(), message, null);
    }

    /**
     * 参数验证失败返回结果
     *
     * @param <T>
     * @return
     */
    public static <T> Result<T> validateFailed() {
        return new Result<>(ResultCode.BAD_REQUEST.getCode(), ResultCode.BAD_REQUEST.getMessage(), null);
    }

    /**
     * 参数验证失败返回结果
     *
     * @param message 提示信息
     * @param <T>
     * @return
     */
    public static <T> Result<T> validateFailed(String message) {
        return new Result<>(ResultCode.BAD_REQUEST.getCode(), message, null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
